package cn.sc.summer.token.util;

import cn.hutool.core.collection.ListUtil;
import cn.sc.summer.token.encrypt.TokenUtil;
import cn.sc.summer.token.enums.RequestTypeEnum;
import cn.sc.summer.constant.project.ProjectConstant;
import cn.sc.summer.constant.token.TokenConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 接口：请求头组装工具类
 *
 * @author a-xin
 * @date 2024/8/26 13:09
 */
@Slf4j
@Component
public class HeaderUtil {

    /**
     * 获取openfeign请求header信息
     *
     * @return header信息
     */
    public static Map<String, String> getFeignHeader() {
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put(TokenConstant.REQUEST_TYPE, RequestTypeEnum.OPEN_FEIGN.getType());
        headerMap.put(TokenConstant.API_KEY_REQUEST_HEADER, TokenUtil.getApiEncryptKey(16, ProjectConstant.SERVER_NAME, RequestTypeEnum.OPEN_FEIGN));
        return headerMap;
    }

    /**
     * 获取openfeign请求header信息
     *
     * @return header信息
     */
    public static Map<String, List<String>> getFeignHeaderList() {
        Map<String, List<String>> headerMap = new HashMap<>();
        headerMap.put(TokenConstant.REQUEST_TYPE, ListUtil.of(RequestTypeEnum.OPEN_FEIGN.getType()));
        headerMap.put(TokenConstant.API_KEY_REQUEST_HEADER, ListUtil.of(TokenUtil.getApiEncryptKey(16, ProjectConstant.SERVER_NAME, RequestTypeEnum.OPEN_FEIGN)));
        return headerMap;
    }

}
